package com.rahwi.rahwi_server.Utils.Converter;

import com.rahwi.rahwi_server.DefineEntity.HomePost;
import com.rahwi.rahwi_server.Entity.Post;
import com.rahwi.rahwi_server.vo.data.BaseNumber;
import com.rahwi.rahwi_server.vo.data.BasePost;
import com.rahwi.rahwi_server.vo.data.HomePostContainUser;
import com.rahwi.rahwi_server.vo.data.IPost;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName PostConverter
 * @Description 将实体类转换为前端所需数据对象
 * @Date 2021/12/10 12:29
 * @Autor mjw
 * @Version 1.0
 */
public class PostConverter {

//    public static

    public static IPost toVoPost(Post post, ICopy<? extends IPost,Post> iCopy){
        return iCopy.Copy(post);
    }

    public static List<IPost> toVoPost(List<Post> posts, ICopy<IPost,Post> iCopy){
        List<IPost> iPosts = new ArrayList<IPost>();
        for (Post post: posts) {
            iPosts.add(toVoPost(post,iCopy));
        }
        return iPosts;
    }

    /**
     * @Description 将自定义返回实体转换为前端所需对象，主页加载所需item
     * @Date 2021/12/15 21：57
     * @Autor dn
     * @Version 1.0
     */
    public static HomePostContainUser toVoHomePost(List<HomePost> post, int pageSize){
        HomePostContainUser result = new HomePostContainUser();
        result.setList(post);
        result.setPagesize(pageSize);
        return result;
    }

    /**
     * @Description 查询贴子数量结果，转换方法
     * @Date 2021/12/17 16：16
     * @Autor dn
     * @Version 1.0
     */
    public static BaseNumber toVoPostNumber(int postNumber){
        BaseNumber result = new BaseNumber();
        result.setNumber(postNumber);
        return result;
    }


}
